package study.rocketmq.stream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;
import study.rocketmq.source.OrderSource;
import study.rocketmq.vo.Order;

/***
 * 通过Spring Cloud Stream 发送消息
 */
@Service
public class SpringCloudStreamSourceService {
    @Autowired
    Source source;
    @Autowired
    OrderSource orderSource;

    public void send(String msg){
        MessageBuilder builder = MessageBuilder.withPayload(msg);
        Message message = builder.build();
        source.output().send(message);
        System.out.println("发送消息成功...");
    }

    /**
     * 发送对象 -Order
     * @param order
     */
    public void send(Order order){
        MessageBuilder builder = MessageBuilder.withPayload(order);
        Message message = builder.build();
        orderSource.output().send(message);
        System.out.println("发送Order消息成功...");
    }

}
